<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="DialogFormVisibleCom" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="dataForm" :model="formSubmitDataCom" :rules="rules" label-position="right" label-width="100px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 字典标识 -->
            <el-form-item label="用户名称:" prop="user_name">
              <el-input v-model="formSubmitDataCom.user_name" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 字典名称 -->
            <el-form-item label="用户编号:" prop="user_code">
              <el-input v-model="formSubmitDataCom.user_code" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 字典对照编码 -->
            <el-form-item label="机构名称:" prop="branch_code">
              <!-- <el-select v-model="branch_code" filterable placeholder="请选择">
                <el-option
                  v-for="item in branchnameOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select> -->
              <el-cascader
                v-model="formSubmitDataCom.branch_code"
                :options="branchnameOptions"
                :props="{ emitPath: false ,checkStrictly: true}"
              ></el-cascader>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 字典对照名称 -->
            <el-form-item label="所属法人:" prop="lp_code">
              <el-select v-model="formSubmitDataCom.lp_code" multiple placeholder="请选择">
                <el-option
                  v-for="item in lpnameOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="24">
            <el-form-item label="备注:" prop="remark">
              <el-input v-model="formSubmitDataCom.remark" placeholder="Please select" type="textarea"></el-input>
            </el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'

export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    // tableColumn: {
    //     type: Array,
    //     default() {
    //         return []
    //     }
    // },
    formSubmitData: {
      type: Object,
      default: function () {
        return {
        }
      }
    },
    lpnameOptions:{ //法人
      type:Array
    },
    branchnameOptions:{ //机构
      type:Array
    }
  },
  // 定义属性
  data() {
    return {
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        // flag: [{required: true, message: '字典标识必填', trigger: 'change'}],
        // flag_name: [{required: true, message: '字典名称必填', trigger: 'change'}],
        // code: [{required: true, message: '字典对照编码必填', trigger: 'change'}],
        // name: [{required: true, message: '字典对照名称必填', trigger: 'change'}],
        // type: [{ required: true, message: 'type is required', trigger: 'change' }],
        // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      // 表单用到的值
      // calendarTypeOptions,
      // statusOptions: ['published', 'draft', 'deleted'],
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    resetFormData() {
      this.$emit('resetFormDataEmit')
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')
        }
      })
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitData, "_XID");
          const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')
        }
      })
    },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>